package crafex.resource.items.gunparts;

import crafex.engine.tools.IntVertex2D;
import crafex.engine.tools.Range;

public class Receiver extends GunPart{
	
	/**
	 * speed the bolt moves
	 */
	public float boltSpeed;
	public Range g_boltSpeed;
	public String s_blotSpeed = "-boltspeed=";
	public String s_connectStock = "-connectstock=";
	public IntVertex2D connectStock;
	public String s_connectMag = "-connectmag=";
	public IntVertex2D connectMag;
	public String s_connectGrip = "-connectgrip=";
	public IntVertex2D connectGrip;
	public String s_connectTrigger = "-connecttrigger=";
	public IntVertex2D connectTrigger;
	public String s_connectBarrel = "-connectbarrel=";
	public IntVertex2D connectBarrel;
	public float bulletSize;
	public String s_bulletSize;
	
	public boolean chromePlated;
	public boolean g_chromePlated;
	public String s_chromePlated;
	
	public Receiver(int id) {
		super(id, new IntVertex2D(2, 1));
		//TODO work on gunparts starting here
		
	}
	
	@Override
	public String[] save(String name){
		String[] data = new String[14];
		data[0] = name;
		data[1] = s_name + this.name;
		data[2] = s_brandID + brandID;
		data[3] = s_image + imagefilename;
		data[4] = s_connectStock + connectStock.getX() + "," + connectStock.getY();
		data[5] = s_connectBarrel + connectBarrel.getX() + "," + connectBarrel.getY();
		data[6] = s_connectGrip + connectGrip.getX() + "," + connectGrip.getY();
		data[7] = s_connectTrigger + connectTrigger.getX() + "," + connectTrigger.getY();
		data[8] = s_connectMag + connectMag.getX() + "," + connectMag.getY();
		data[9] = s_rareChance + rareChance;
		data[10] = s_blotSpeed + g_boltSpeed.getLowest() + "," + g_boltSpeed.getHighest();
		data[11] = s_bulletSize + bulletSize;
		data[12] = s_chromePlated + g_chromePlated;
		data [13] = s_waterproof + g_waterproof;
		
		return data;
	}
	
	@Override
	public void load(String[] save) {
		for(int i = 0; i < save.length; i++){
			if(save[i].contains(s_name)){
				name = save[i].substring(s_name.length());
			}
			if(save[i].contains(s_blotSpeed)){
				g_boltSpeed.setLowest(Integer.getInteger(save[i].substring(s_blotSpeed.length(), save[i].indexOf(","))));
				g_boltSpeed.setHighest(Integer.getInteger(save[i].substring(save[i].indexOf(","))));
			}
			if(save[i].contains(s_bulletSize)){
				bulletSize = Integer.getInteger(save[i].substring(s_bulletSize.length()));
			}
			if(save[i].contains(s_chromePlated)){
				g_chromePlated = Boolean.getBoolean(save[i].substring(s_chromePlated.length()));
			}
			if(save[i].contains(s_waterproof)){
				g_waterproof = Boolean.getBoolean(save[i].substring(s_waterproof.length()));
			}
			if(save[i].contains(s_rareChance)){
				rareChance = Integer.getInteger(save[i].substring(s_rareChance.length()));
			}
			if(save[i].contains(s_brandID)){
				brandID = save[i].substring(s_brandID.length());
			}
			if(save[i].contains(s_image)){
				imagefilename = save[i].substring(s_image.length());
			}
			if(save[i].contains(s_connectStock)){
				connectStock.setX(Integer.getInteger(save[i].substring(s_connectStock.length(), save[i].indexOf(","))));
				connectStock.setY(Integer.getInteger(save[i].substring(save[i].indexOf(",")+1)));
			}
			if(save[i].contains(s_connectBarrel)){
				connectBarrel.setX(Integer.getInteger(save[i].substring(s_connectBarrel.length(), save[i].indexOf(","))));
				connectBarrel.setY(Integer.getInteger(save[i].substring(save[i].indexOf(",")+1)));
			}
			if(save[i].contains(s_connectGrip)){
				connectGrip.setX(Integer.getInteger(save[i].substring(s_connectGrip.length(), save[i].indexOf(","))));
				connectGrip.setY(Integer.getInteger(save[i].substring(save[i].indexOf(",")+1)));
			}
			if(save[i].contains(s_connectMag)){
				connectMag.setX(Integer.getInteger(save[i].substring(s_connectMag.length(), save[i].indexOf(","))));
				connectMag.setY(Integer.getInteger(save[i].substring(save[i].indexOf(",")+1)));
			}
			if(save[i].contains(s_connectTrigger)){
				connectTrigger.setX(Integer.getInteger(save[i].substring(s_connectTrigger.length(), save[i].indexOf(","))));
				connectTrigger.setY(Integer.getInteger(save[i].substring(save[i].indexOf(",")+1)));
			}
		}
		
	}
	
	@Override
	public void generate(int level) {
		
		
	}
}
